var koa = require('koa');
var app = new koa();
var path= require('path');
var router = require('koa-route');
const koaStatic = require('koa-static');
var request = require('request');

app
.use(router.get('/ttt',(ctx)=>{
	console.log("aaaaaaaaa");
	ctx.body="aaa@@@"
}))
.use(router.get('/data',(ctx)=>{
	var options = {
		url: 'https://api.github.com/repos/request/request',
		headers: {
			'User-Agent': 'request'
		}
	};
	request(options, (error, response, body)=>{
		console.log(body);
		console.log(response.body);
	});
}))
.use(koaStatic(path.resolve(__dirname,'./static')));

// logger
app.use(function *(next){
	var start = new Date;
	yield next;
	var ms = new Date - start;
	console.log('%s %s - %s', this.method, this.url, ms);
});

exports.app=app
app.listen(3000);

